package com.ruoyi.examination.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.examination.vo.QuestionGroupSelectVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.examination.domain.QuestionGroup;
import com.ruoyi.examination.service.IQuestionGroupService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 题组管理Controller
 *
 * @author hcc
 * @date 2025-10-21
 */
@RestController
@RequestMapping("/questionGroup")
public class QuestionGroupController extends BaseController
{
    @Autowired
    private IQuestionGroupService questionGroupService;

    /**
     * 查询题组管理列表
     */
    @RequiresPermissions("examination:questionGroup:list")
    @GetMapping("/list")
    public TableDataInfo list(QuestionGroup questionGroup)
    {
        startPage();
        List<QuestionGroup> list = questionGroupService.selectQuestionGroupList(questionGroup);
        return getDataTable(list);
    }

    /**
     * 导出题组管理列表
     */
    @RequiresPermissions("examination:questionGroup:export")
    @Log(title = "题组管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QuestionGroup questionGroup)
    {
        List<QuestionGroup> list = questionGroupService.selectQuestionGroupList(questionGroup);
        ExcelUtil<QuestionGroup> util = new ExcelUtil<QuestionGroup>(QuestionGroup.class);
        util.exportExcel(response, list, "题组管理数据");
    }

    /**
     * 获取题组管理详细信息
     */
    @RequiresPermissions("examination:questionGroup:query")
    @GetMapping(value = "/{groupId}")
    public AjaxResult getInfo(@PathVariable("groupId") String groupId)
    {
        return success(questionGroupService.selectQuestionGroupByGroupId(groupId));
    }

    /**
     * 新增题组管理
     */
    @RequiresPermissions("examination:questionGroup:add")
    @Log(title = "题组管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QuestionGroup questionGroup)
    {
        return toAjax(questionGroupService.insertQuestionGroup(questionGroup));
    }

    /**
     * 修改题组管理
     */
    @RequiresPermissions("examination:questionGroup:edit")
    @Log(title = "题组管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QuestionGroup questionGroup)
    {
        return toAjax(questionGroupService.updateQuestionGroup(questionGroup));
    }

    /**
     * 题组关联题目
     */
    @RequiresPermissions("examination:questionGroup:edit")
    @Log(title = "题组管理", businessType = BusinessType.UPDATE)
    @PutMapping("/associationQuestion")
    public AjaxResult associationQuestion(@RequestBody QuestionGroup questionGroup)
    {
        return toAjax(questionGroupService.associationQuestion(questionGroup));
    }

    /**
     * 删除题组管理
     */
    @RequiresPermissions("examination:questionGroup:remove")
    @Log(title = "题组管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{groupIds}")
    public AjaxResult remove(@PathVariable String[] groupIds)
    {
        return toAjax(questionGroupService.deleteQuestionGroupByGroupIds(groupIds));
    }

    /**
     * 查询题组管理列表
     */
    @RequiresPermissions("examination:questionGroup:list")
    @GetMapping("/getList")
    public TableDataInfo getList(QuestionGroupSelectVo questionGroupSelectVo)
    {
        List<QuestionGroup> list = questionGroupService.getList(questionGroupSelectVo);
        return getDataTable(list);
    }

    /**
     * 题组取消关联题目
     */
    @RequiresPermissions("examination:questionGroup:edit")
    @Log(title = "题组管理", businessType = BusinessType.UPDATE)
    @PutMapping("/cancelAssociationQuestion")
    public AjaxResult cancelAssociationQuestion(@RequestBody QuestionGroup questionGroup)
    {
        return toAjax(questionGroupService.cancelAssociationQuestion(questionGroup));
    }
}
